package com.hliushi.bookmanager;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication
@MapperScan(basePackages = "com.hliushi.bookmanager.mapper")
@ServletComponentScan("com.hliushi.bookmanager.config")
public class BookmanagerApplication {

    public static Logger log = LoggerFactory.getLogger(BookmanagerApplication.class);

    // 修改内容: 启动类添加了一条注释
    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext context = SpringApplication.run(BookmanagerApplication.class, args);

        // 启动完成后, 在控制台提示项目启动成功, 并且输出当前服务对应的swagger接口文档地址
        // environment 可以获取配置文件中的信息
        ConfigurableEnvironment env = context.getEnvironment();
        String appName = env.getProperty("spring.application.name");
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        //
        String protocol = "http";
        log.info(
                "\n----------------------------------------------------------\n\t"
                        + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t{}://localhost:{}\n\t"
                        + "External: \t{}://{}:{}\n\t"
                        + "Swagger: \t{}://localhost:{}/doc.html\n\t"
                        + "Profile(s): \t{}\n----------------------------------------------------------",
                appName, protocol, port, protocol, hostAddress, port, protocol, port, env.getActiveProfiles());

    }

}
